import {Controller, Render, Get, UseBefore, Session} from "routing-controllers";
import { utils } from "../../utils/utils";
import { Service, Inject } from "typedi";
import { CourseServiceImpl } from "../../service/impl/CourseServiceImpl";
import { NewsServiceImpl } from "../../service/impl/NewsServiceImpl";

@Service()
@Controller()
export class IndexControllerHome {
  
  @Inject()
  private courseServiceImpl: CourseServiceImpl;
  
  @Inject()
  private newsServiceImpl: NewsServiceImpl;
  
  @Get("/")
  @Render("home/page/index")
  public async Index(@Session() session,) {
    return {
      title: utils.titleName("首页"),
      isShowAction: {
        header: true,
        footer: true
      },
      banner: {
        bannerTitle: '怪客课堂',
        bannerUrl: '/img/banner.png',
      },
      newCourse: await this.courseServiceImpl.getIndexCourse(),
      newsList: await this.newsServiceImpl.getNews(),
      login: session.user ? session.user : false
    }
  }
}